package com.education.welco.service.impl;

import com.education.common.utils.Convert;
import com.education.welco.mapper.UserStarMapper;
import com.education.welco.pojo.PlatformResources;
import com.education.welco.pojo.UserStar;
import com.education.welco.pojo.vo.UserStarVo;
import com.education.welco.service.IUserStarService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 资源用户星标（收藏关联） 服务层实现
 *
 * @Author: liftsail
 * @Date: 2022-09-23
 * @Description: 不积跬步无以至千里
 */
@Service
public class UserStarServiceImpl implements IUserStarService {

    @Autowired
    private UserStarMapper userStarMapper;

    /**
     * 查询资源用户星标（收藏关联）信息
     *
     * @param id 资源用户星标（收藏关联）ID
     * @return 资源用户星标（收藏关联）信息
     */
    @Override
    public UserStar selectUserStarById(Integer id) {
        return userStarMapper.selectUserStarById(id);
    }

    /**
     * 查询资源用户星标（收藏关联）列表
     *
     * @param userStar 资源用户星标（收藏关联）信息
     * @return 资源用户星标（收藏关联）集合
     */
    @Override
    public List<UserStar> selectUserStarList(UserStar userStar) {
        return userStarMapper.selectUserStarList(userStar);
    }

    /**
     * 新增资源用户星标（收藏关联）
     *
     * @param userStarVo 资源用户星标（收藏关联）信息
     * @return 结果
     */
    @Override
    public int insertUserStar(UserStarVo userStarVo) {
        userStarVo.setCreateTime(new Date());
        return userStarMapper.insertUserStar(userStarVo);
    }

    /**
     * 批量新增资源用户星标（收藏关联）
     *
     * @param resIdListUserNow 资源用户星标（收藏关联）信息
     * @return 结果
     */
    @Override
    public int batchInsertUserStarByResIdListAndUserId(List<String> resIdListUserNow, Integer userId, Boolean isDelete) {
        return userStarMapper.batchInsertUserStarByResIdListAndUserId(resIdListUserNow,userId,isDelete);
    }

    /**
     * 修改资源用户星标（收藏关联）
     *
     * @param userStar 资源用户星标（收藏关联）信息
     * @return 结果
     */
    @Override
    public int updateUserStar(UserStar userStar) {
        return userStarMapper.updateUserStar(userStar);
    }

    /**
     * 删除资源用户星标（收藏关联）对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteUserStarByIds(String ids) {
        return userStarMapper.deleteUserStarByIds(Convert.toStrArray(ids));
    }

    @Override
    public UserStar selectUserStarByResIdAndUserId(String resId, Integer userId) {
        return userStarMapper.selectUserStarByResIdAndUserId(resId, userId);
    }

    @Override
    public List<UserStar> selectUserStarByUserIdAndResidList(Integer userId, List<String> resIdList) {
        return userStarMapper.selectUserStarByUserIdAndResidList(userId, resIdList);
    }

    @Override
    public int deleteUserStarByResIdAndUserId(String resId, Integer userId) {
        return userStarMapper.deleteUserStarByResIdAndUserId(resId, userId);
    }

    @Override
    public int batchDeleteUserStarByResIdsAndUserId(List<String> resIdList, Integer userId) {
        return userStarMapper.batchDeleteUserStarByResIdsAndUserId(resIdList, userId);
    }

    @Override
    public int batchUpdateUserStarByResIdListAndUserId(List<String> resIdListBefore, Integer userId, Boolean isDelete) {
        return userStarMapper.batchUpdateUserStarByResIdListAndUserId(resIdListBefore, userId, isDelete);
    }

    @Override
    public int updateUserStarByResIdAndUserId(UserStar userStarcp) {
        return userStarMapper.updateUserStarByResIdAndUserId(userStarcp);
    }

    @Override
    public List<PlatformResources> selectShareSchoolResListForStarByTeaId(Integer teaId, Integer pageNum, Integer pageSize) {
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }
        return userStarMapper.selectShareSchoolResListForStarByTeaId(teaId);
    }
}